package com.dung.travel.adapters;


import java.util.ArrayList;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.dung.travel.R;
import com.dung.travel.objects.ListItem;

public class ListAdapter extends ArrayAdapter<ListItem> {
	private Context context;
	private ArrayList<ListItem> postList;

	public ListAdapter(Context context, int textViewResourceId,
			ArrayList<ListItem> objects) {
		super(context, textViewResourceId, objects);
		this.context = context;
		this.postList = objects;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		View v = convertView;
		if (v == null) {
			LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
			v = inflater.inflate(R.layout.list_item,null);
		}

		final ListItem o = postList.get(position);
		if (o != null) {

			TextView lblTitle = (TextView) v.findViewById(R.id.tv_title);
			if (lblTitle != null) {
				lblTitle.setText(o.getTitle());
			}
			TextView lblDes = (TextView) v.findViewById(R.id.tv_description);
			if (lblDes != null) {
				lblDes.setText(o.getDescription());
			}
			ImageView imgThumbnail = (ImageView) v.findViewById(R.id.img_thumbnail);
			if (imgThumbnail != null) {
				imgThumbnail.setImageResource(o.getThumbnail());
			}
		}
		return v;
	}

}
